<?php //include "function.php"; ?>
<head>
<!--[if lt IE 9]>
<script src="asset/js/html5.js"></script>
<script src="asset/js/PIE.js"></script>
<![endif]-->
<!-- jquerytools -->
<script src="<?php echo base_url();?>asset/js/jquery.tools.min.js"></script>
<script src="<?php echo base_url();?>asset/js/jquery.ui.min.js"></script>

<!--[if lte IE 9]>
<link rel="stylesheet" media="screen" href="asset/css/ie.css" />
<script type="text/javascript" src="asset/js/ie.js"></script>
<![endif]-->
</head>
<h2>Mengirim SMS</h2>

<form method="post" action="<?php echo base_url();?>sms_gateway/konfigurasi/1/submit">
<table>
<tr valign="top"><td><b>Pilih Group</b></td><td>:</td><td>
<select name='group'>
<option value="Mahasiswa">
Mahasiswa
</option>
</select>
</td></tr>
<tr valign="top"><td><b>Nama!</b></td><td>:</td><td><input type="text" name="namae"></td></tr>
<tr valign="top"><td><b>Masukkan No HP Tujuan</b></td><td>:</td><td><input type="text" name="nohp"></td></tr>
<tr valign="top"><td><b>Kirim Melalui Modem/HP</b></td><td>:</td><td><?php echo service3(''); ?></td></tr>
<tr valign="top"><td><b>Masukkan isi SMS</b><br>(maksimum panjang SMS adalah 160 karakter)</td><td>:</td><td><textarea name="sms" rows="5" cols="40" maxlength="160"></textarea></td></tr>

</table>
<input type="submit" name="submit" value="Kirim SMS">
</form>

<?php
$id = $this->uri->segment(4);
//if ($_POST['submit'])
if ($id == "submit")
  {
   $nohp = $_POST['nohp'];
   $sms = $_POST['sms'];
   $phone = $_POST['phoneid'];
   
   echo "<b>Status :</b><br>";
   echo "<pre>";
   passthru('gammu-smsd-inject -c '.$phone.' TEXT '.$nohp.' -text "'.$sms.'"');
   echo "</pre>";
  }
?> 				

<?php
function service3($x)
{
   $string = "<select name='phoneid'>";
   $handle = @fopen($path."smsdrc1", "r");
   while (!feof($handle)) 
   {
        $buffer = fgets($handle);
        if (substr_count($buffer, 'phoneid = ') > 0)
		{
		   $split = explode("phoneid = ", $buffer);
		   $id1 = str_replace("\r\n", "", $split[1]);
		}
   }	
   if ($id1 != '') {
   $string .= "<option value='smsdrc1'>".$id1."</option>";
   }
   fclose($handle);
   
   $handle = @fopen($path."smsdrc2", "r");
   while (!feof($handle)) 
   {
        $buffer = fgets($handle);
        if (substr_count($buffer, 'phoneid = ') > 0)
		{
		   $split = explode("phoneid = ", $buffer);
		   $id2 = str_replace("\r\n", "", $split[1]);
		}
   }	
   if ($id2 != '') {
   $string .= "<option value='smsdrc2'>".$id2."</option>";   
   }
   fclose($handle);
   
   $handle = @fopen($path."smsdrc3", "r");
   while (!feof($handle)) 
   {
        $buffer = fgets($handle);
        if (substr_count($buffer, 'phoneid = ') > 0)
		{
		   $split = explode("phoneid = ", $buffer);
		   $id3 = str_replace("\r\n", "", $split[1]);
		}
   }	
   if ($id3 != '') {
   $string .= "<option value='smsdrc3'>".$id3."</option>";
   }
   fclose($handle);
   
   $handle = @fopen($path."smsdrc4", "r");
   while (!feof($handle)) 
   {
        $buffer = fgets($handle);
        if (substr_count($buffer, 'phoneid = ') > 0)
		{
		   $split = explode("phoneid = ", $buffer);
		   $id4 = str_replace("\r\n", "", $split[1]);
		}
   }	
   if ($id4 != '') {
   $string .= "<option value='smsdrc4'>".$id4."</option>";
   }
   fclose($handle);
   
   $string .= "</select>";
   return $string;
}
?>